﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Clipper.BLL;

namespace Clipper.ClipperUserControl
{
    /// <summary>
    /// UserLog.xaml 的交互逻辑
    /// </summary>
    public partial class UserLog : UserControl
    {
        #region 变量
        SystemLog mSystemLogBll = new SystemLog();
        #endregion
        public UserLog()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            string dateStart, dateEnd;
            string logLevel = "";

            if (dtpStart.SelectedDate == null)
            {
                UIHelper.ShowKeyMessage("StartDateTip");
                return;
            }
            if (dtpEnd.SelectedDate == null)
            {
                UIHelper.ShowKeyMessage("EndDateTip");
                return;
            } 
            dateStart = dtpStart.SelectedDate.Value.ToString("yyyy-MM-dd");
            dateEnd = dtpEnd.SelectedDate.Value.ToString("yyyy-MM-dd");
            logLevel = cboLogLevel.Text;
            datLog.ItemsSource= mSystemLogBll.GetLog(logLevel, dateStart, dateEnd);
        }

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            if (UIHelper.ShowKeyAskMessage("IsDelete"))
            {
                string dateStart, dateEnd;
                string logLevel = "";
                if (dtpStart.SelectedDate == null)
                {
                    UIHelper.ShowKeyMessage("StartDateTip");
                    return;
                }
                if (dtpEnd.SelectedDate == null)
                {
                    UIHelper.ShowKeyMessage("EndDateTip");
                    return;
                }
                dateStart = dtpStart.SelectedDate.Value.ToString("yyyy-MM-dd");
                dateEnd = dtpEnd.SelectedDate.Value.ToString("yyyy-MM-dd");
                logLevel = cboLogLevel.Text;
                mSystemLogBll.DeleteLog(dateStart, dateEnd);
                datLog.ItemsSource = mSystemLogBll.GetLog(logLevel, dateStart, dateEnd);
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (cboLogLevel.Items.Count == 0)
            {
                cboLogLevel.Items.Add("消息");
                cboLogLevel.Items.Add("警告");
                cboLogLevel.Items.Add("错误");
            }
        }
    }
}
